package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.bean.Member;
import com.atguigu.dao.MemberMapper;
import com.atguigu.service.MemberService;
import com.atguigu.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;


@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberMapper memberMapper;


    @Override
    public Member findByTelephone(String telephone) {
        return memberMapper.findByTelephone(telephone);
    }

    @Override
    public void add(Member member) {
        memberMapper.add(member);
    }

    @Override
    public List<Integer> findMemberCountByMonth(List<String> list) {
        List<Integer> memberCountList = new ArrayList<>();
        if (list != null && list.size()>0){
            for (String month : list) {
                String lastDayOfMonth = DateUtils.getLastDayOfMonth(month);
                Integer memberCount =memberMapper.findMemberCountByMonth(lastDayOfMonth);
                memberCountList.add(memberCount);
            }
        }
        return memberCountList;
    }
}
